package h0719;

import java.util.Scanner;
/**
  * @description 来自异国的客人，进制转换问题
  * @author 不知名帅哥
  * @date 2024/7/19 22:39
  * @version 1.0
*/
public class GuestFromAnotherCountry {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();  //价值  //如果太大换成long
        int n = sc.nextInt();    //幸运数字
        int m = sc.nextInt();    //该国的进制

        int res = getResult(k, n, m);
        System.out.println(res);
    }

    private static int getResult(int k, int n, int m) {
        if (n>=m){
            return 0;
        }
        int count=0;
        while (k!=0){
            int remainder = k % m;
            if (remainder==n){  //只需要计算出当前余数等于n就可以
                count++;
            }
            k = k / m;
        }
//        System.out.println(string);
        return count;
    }
}
